home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10703 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Capturing useful return values from the parallel port
  5. Date: 19 Mar 1996 07:47 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <19MAR199607471267@erich.triumf.ca>
  9. References: <4ilur8$hgi@lyra.csx.cam.ac.uk>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4ilur8$hgi@lyra.csx.cam.ac.uk>, mae20@cus.cam.ac.uk (M.A. Elliott) writes...
  14. >I am building a small routine which is designed to return values 1-4 from a four
  15. >button resposne box plugged into the parallel port. The buttons normally return
  16. >bits 0 through 3 but I am having problems converting these, elegantly, into the 
  17. >required values. 
  18. >@define PORTID  0x379
  19. >unsigned pressedKey(void)
  20. >                    {
  21. >                       return ((inportb(PORTID) >> 6) ^1);
  22.  
  23. If the switches are in bits 0 - 3, this shift will throw them away!
  24.  
  25. How about:
  26.     switch(inport(PORTID)) {
  27.         case 1: /* switch 1 hit  */
  28.             break;
  29.         case 2: /* switch 2 hit */
  30.             break;
  31.         case 4: /* switch 3 hit  */
  32.             break;
  33.         case 8: /* switch 4 hit  */
  34.             break;
  35.         default: /* nothing interesting happened  */
  36.             break;
  37.         }
  38.  
  39. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  40. Internet: bennett@triumf.ca         | of one another only when one can be
  41. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  42. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  43. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  44. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  45.  
  46.